//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Xml;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    ///<summary>
    /// Gives access to the standard table styles.
    ///</summary>
    public static class TableStyles
    {
        static void BuildTableStyles()
        {
            _builtInStyles = new Dictionary<string, TableStyle>();
            string s = TableStyleResources.presetTableStyles;
            using (var reader = new StringReader(s))
            {
                using (XmlReader xmlReader = new XmlTextReader(reader))
                {
                    var context = new ReadContext(xmlReader, null);
                    using (ReadContext presetTableStyles = context.Read("presetTableStyles"))
                    {
                        while (presetTableStyles.ReaderLocalName != null)
                        {
                            using (ReadContext container = presetTableStyles.Read(presetTableStyles.ReaderLocalName)
                                )
                            {
                                List<DifferentialStyleRecord> dxfs =
                                    container.ReadOptionalListElement<DifferentialStyleRecord>("dxfs", "dxf");
                                container.AddData(new DifferentialStyleRecordResolver(dxfs, 1));
                                var tableStyles = new List<TableStyle>();
                                if (container.ReaderLocalName == "tableStyles")
                                {
                                    using (ReadContext tableStylesContext = container.Read("tableStyles"))
                                    {
                                        while (tableStylesContext.ReaderLocalName == "tableStyle")
                                        {
                                            tableStyles.Add(
                                                tableStylesContext.ReadElement(() => new TableStyle(true)));
                                        }
                                    }
                                }
//                                List<TableStyle> tableStyles =
  //                                  container.ReadOptionalListElement<TableStyle>("tableStyles", "tableStyle");
                                
                                foreach (var tableStyle in tableStyles)
                                {
                                    BuiltInStyles.Add(tableStyle.Name, tableStyle);
                                }
                            }
                        }
                    }
                }
            }
        }

        internal static TableStyle GetStyle (string name)
        {
            Contract.Requires(name != null);
            return BuiltInStyles[name];
        }
        static Dictionary<string, TableStyle> _builtInStyles ;
        internal static Dictionary<string, TableStyle> BuiltInStyles
        {
            get
            {
                if (_builtInStyles == null)
                    BuildTableStyles();
                return _builtInStyles;
            }
        }
        public static TableStyle Medium28
        {
            get
            {
                return BuiltInStyles["TableStyleMedium28"];
            }
        }
public static TableStyle Medium27{get{return BuiltInStyles["TableStyleMedium27"];}}
public static TableStyle Medium26{get{return BuiltInStyles["TableStyleMedium26"];}}
public static TableStyle Medium25{get{return BuiltInStyles["TableStyleMedium25"];}}
public static TableStyle Medium24{get{return BuiltInStyles["TableStyleMedium24"];}}
public static TableStyle Medium23{get{return BuiltInStyles["TableStyleMedium23"];}}
public static TableStyle Medium22{get{return BuiltInStyles["TableStyleMedium22"];}}
public static TableStyle Medium21{get{return BuiltInStyles["TableStyleMedium21"];}}
public static TableStyle Medium20{get{return BuiltInStyles["TableStyleMedium20"];}}
public static TableStyle Medium19{get{return BuiltInStyles["TableStyleMedium19"];}}
public static TableStyle Medium18{get{return BuiltInStyles["TableStyleMedium18"];}}
public static TableStyle Medium17{get{return BuiltInStyles["TableStyleMedium17"];}}
public static TableStyle Medium16{get{return BuiltInStyles["TableStyleMedium16"];}}
public static TableStyle Medium15{get{return BuiltInStyles["TableStyleMedium15"];}}
public static TableStyle Medium14{get{return BuiltInStyles["TableStyleMedium14"];}}
public static TableStyle Medium13{get{return BuiltInStyles["TableStyleMedium13"];}}
public static TableStyle Medium12{get{return BuiltInStyles["TableStyleMedium12"];}}
public static TableStyle Medium11{get{return BuiltInStyles["TableStyleMedium11"];}}
public static TableStyle Medium10{get{return BuiltInStyles["TableStyleMedium10"];}}
public static TableStyle Medium9{get{return BuiltInStyles["TableStyleMedium9"];}}
public static TableStyle Medium8{get{return BuiltInStyles["TableStyleMedium8"];}}
public static TableStyle Medium7{get{return BuiltInStyles["TableStyleMedium7"];}}
public static TableStyle Medium6{get{return BuiltInStyles["TableStyleMedium6"];}}
public static TableStyle Medium5{get{return BuiltInStyles["TableStyleMedium5"];}}
public static TableStyle Medium4{get{return BuiltInStyles["TableStyleMedium4"];}}
public static TableStyle Medium3{get{return BuiltInStyles["TableStyleMedium3"];}}
public static TableStyle Medium2{get{return BuiltInStyles["TableStyleMedium2"];}}
public static TableStyle Medium1{get{return BuiltInStyles["TableStyleMedium1"];}}
public static TableStyle Light21{get{return BuiltInStyles["TableStyleLight21"];}}
public static TableStyle Light20{get{return BuiltInStyles["TableStyleLight20"];}}
public static TableStyle Light19{get{return BuiltInStyles["TableStyleLight19"];}}
public static TableStyle Light18{get{return BuiltInStyles["TableStyleLight18"];}}
public static TableStyle Light17{get{return BuiltInStyles["TableStyleLight17"];}}
public static TableStyle Light16{get{return BuiltInStyles["TableStyleLight16"];}}
public static TableStyle Light15{get{return BuiltInStyles["TableStyleLight15"];}}
public static TableStyle Light14 {get{return BuiltInStyles["TableStyleLight14 "];}}
public static TableStyle Light13{get{return BuiltInStyles["TableStyleLight13"];}}
public static TableStyle Light12{get{return BuiltInStyles["TableStyleLight12"];}}
public static TableStyle Light11{get{return BuiltInStyles["TableStyleLight11"];}}
public static TableStyle Light10{get{return BuiltInStyles["TableStyleLight10"];}}
public static TableStyle Light9{get{return BuiltInStyles["TableStyleLight9"];}}
public static TableStyle Light8{get{return BuiltInStyles["TableStyleLight8"];}}
public static TableStyle Light7{get{return BuiltInStyles["TableStyleLight7"];}}
public static TableStyle Light6{get{return BuiltInStyles["TableStyleLight6"];}}
public static TableStyle Light5{get{return BuiltInStyles["TableStyleLight5"];}}
public static TableStyle Light4{get{return BuiltInStyles["TableStyleLight4"];}}
public static TableStyle Light3{get{return BuiltInStyles["TableStyleLight3"];}}
public static TableStyle Light2{get{return BuiltInStyles["TableStyleLight2"];}}
public static TableStyle Light1{get{return BuiltInStyles["TableStyleLight1"];}}
public static TableStyle Dark11{get{return BuiltInStyles["TableStyleDark11"];}}
public static TableStyle Dark10{get{return BuiltInStyles["TableStyleDark10"];}}
public static TableStyle Dark9{get{return BuiltInStyles["TableStyleDark9"];}}
public static TableStyle Dark8{get{return BuiltInStyles["TableStyleDark8"];}}
public static TableStyle Dark7{get{return BuiltInStyles["TableStyleDark7"];}}
public static TableStyle Dark6{get{return BuiltInStyles["TableStyleDark6"];}}
public static TableStyle Dark5{get{return BuiltInStyles["TableStyleDark5"];}}
public static TableStyle Dark4{get{return BuiltInStyles["TableStyleDark4"];}}
///<summary>
/// Dark 3 table style
///</summary>
public static TableStyle Dark3{get{return BuiltInStyles["TableStyleDark3"];}}
public static TableStyle Dark2{get{return BuiltInStyles["TableStyleDark2"];}}
public static TableStyle Dark1{get{return BuiltInStyles["TableStyleDark1"];}}

    }
}

